package com.houry.spring.bean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Desc
 * @Author houruiyang
 * @Date 2022/3/11
 **/

public class People {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public People(String name) {
        this.name = name;
    }

    public static void main(String[] args) {
        People p1 = new People("MonkeyBrother");
        People p2 = new People("MonkeyBrother");
        People p3 = new People("MonkeyBrother");
        People p4 = new People("MonkeyBrother");
        People p5 = new People("MonkeyBrother");
        List<People> list = new ArrayList<>();

        list.add(p1);
        list.add(p2);
        list.add(p3);
        list.add(p4);
        list.add(p5);


        Map<String, People> collect = list.stream().collect(Collectors.toMap(People::getName, Function.identity()));

        System.out.println(collect.toString());

    }

}
